import categories.CategoriesRegistry;
import categories.CustomerCategory;
import org.apache.log4j.Logger;
import readers.ExcelRowReader;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import com.svcon.jdbf.JDBFException;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class IntelnetParser extends Parser {
    private final static Logger log = Logger.getLogger(SovintelParser.class.toString());

    public IntelnetParser(
            CategoriesRegistry categoriesRegistry,
            File inFile,
            OutputWriters writers
    ) throws IOException, JDBFException, BiffException {
        super(
                "Intelnet parser for " + inFile,
                new ExcelRowReader(Workbook.getWorkbook(inFile)),
                writers,
                categoriesRegistry
        );
    }

    protected void postCorrectValues(CustomerCategory customerCategory, CallRow row) {
        // make postprocessing only for white customers
        if(customerCategory == CustomerCategory.Black) {
            super.postCorrectValues(customerCategory, row);
        }
    }

    private static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("dd.MM.yy HH:mm:ss");

    protected CallRow convertToRow(List<?> values) throws ParseException {
        //ID_Code	Date	Time	Dest	Country	Dial_Num	Duration	Rate	Cost
        return new CallRow(
                Long.parseLong((String) values.get(0)), // cust id
                DATE_TIME_FORMAT.parse(values.get(1) + " " + values.get(2)), // datetime
                Long.parseLong("10" + Long.parseLong((String)values.get(3) + values.get(5))), // dest num
                Double.parseDouble((String) values.get(6))
        );
    }
}